package com.zzc.util;

/**
 * @author fengyi on 2017-10-12.
 *
 */
import java.security.MessageDigest;


/**
 * 
 * Title: [MD5加密工具类]
 */
public class MD5Util {
    /**
     * 
     * Discription:[对字符进行加密]
     * @param inStr 待加密字符串
     * @return 密文
     */
    public final static String encodeMD5(String inStr) {
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
            byte[] byteArray = inStr.getBytes("UTF-8");
            byte[] md5Bytes = md5.digest(byteArray);
            StringBuffer hexValue = new StringBuffer();
            for (int i = 0; i < md5Bytes.length; i++) {
                int val = ((int) md5Bytes[i]) & 0xff;
                if (val < 16) {
                    hexValue.append("0");
                }
                hexValue.append(Integer.toHexString(val));
            }
            return hexValue.toString();
        }
        catch (Exception e) {
            return null;
        }
    }

    /**
     *  
     * Discription:[对字符进行加密，用与系统密码认证和系统数据篡改校验] 
     * @param inStr 待加密字符串
     *  @param secret 系统加密私钥
     * @return 密文
     */
    public final static String encodeMD5WithSecret(String inStr, String secret) {
        return encodeMD5(inStr + secret);
    }

}
